/**
 * 增加菜品
 */

//引入Q模块
var Q = require('q');
//引入公共函数
var util = require('../../util');

//add入口函数
var index = function(getData, postData, config, _redis, db) {
	var deferred = Q.defer();
	//生成32位随机字符串作为菜品ID
	util.createRandomStr(32).then(function(foodId) {
		var foodData = {
			foodId: foodId,
			foodType: postData.foodType,
			foodName: postData.foodName,
			foodPrice: parseInt(postData.foodPrice),
			foodPhoto: postData.fileName,
			foodStatus: 'pushed',
			foodTimestamp: parseInt(Date.now() / 1000),
			foodStock: -1
		};
		db.insert('foodMenu', foodData).then(function(){
			deferred.resolve(1);
		},function(){
			deferred.reject('-0068');
		});
	}, function() {
		deferred.reject('-0069');
	});
	return deferred.promise;
}

//暴露接口
module.exports = {
	index: index
};

